<template>
  <div class="main">
    <span>给您独特的旅行体验</span>
    <div class="sign-up-container">
      <el-form :model="demand" :rules="rules" ref="demand">
        <el-form-item class="input-prepend restyle" prop="destination">
          <div >
            <el-input type="text" placeholder="请填写您想去的目的地" v-model="demand.destination"/>
            <i icon="el-icon-location" />
          </div>
        </el-form-item>

        <el-form-item class="input-prepend" prop="phoneNumber">
          <div>
            <el-input type="text" placeholder="请填写您的手机号码" v-model="demand.phoneNumber"/>
            <i icon="el-icon-mobile-phone" />
          </div>
        </el-form-item>

        <el-form-item>
          <div class="btn">
            <input type="button" class="sign-in-button" value="请帮我定制行程" @click="onSubmit('demand')">
          </div>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import '~/assets/css/sign.css'
import '~/assets/css/iconfont.css'
import demand from "@/api/demand"
export default {
  layout: 'sign',
  data() {
    return {
      demand: {
        destination: "",
        phoneNumber: "",
      },
      rules:{
        destination: [
          { required: true, message: '请输入目的地', trigger: 'blur' }
        ],
        phoneNumber: [
          { required: true, message: '请输入联系方式', trigger: 'blur' }
        ],
      }
    };
  },
  created() {},
  methods: {
    onSubmit(formName) {
      this.$refs[formName].validate((valid) => {
        if(valid){
          console.log("输入的内容", this.demand)
          demand.addDemand(this.demand)
            .then(response => {
              console.log(response)
              this.$message({
                type: 'success',
                message: '您的需求已提交，2小时内会有工作人员联系您，请您留意手机信息!'
              })
              //跳转到登陆页面
              this.$router.push({path: '/'})
            })
        }else{
          return false
        }
      })
      
    },
  },
};
</script>

<style>
</style>